/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

onload=function(){
    if (document.getElementsByClassName == undefined) {
        document.getElementsByClassName = function(className)
        {
            var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
            var allElements = document.getElementsByTagName("*");
            var results = [];

            var element;
            for (var i = 0; (element = allElements[i]) != null; i++) {
                var elementClass = element.className;
                if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
                    results.push(element);
            }

            return results;
        }
    }

}

//parse to XML
function stringtoXML(text){
    var doc;
    if (window.ActiveXObject){ //IE browser only
        doc=new ActiveXObject('Microsoft.XMLDOM');
        doc.async='false';
        doc.loadXML(text);

    } else {    //other browsers
        var parser=new DOMParser();
        doc=parser.parseFromString(text,'text/xml');
    }
    return doc;
}
function xmlToString(xmlDoc) {
    var str;
    if (window.ActiveXObject){ //IE browser only
        str = xmlDoc.xml;

    }else {    //other browsers
        str = (new XMLSerializer()).serializeToString(xmlDoc);
    }
    return str;
}
function userResolver(){
    return "http://xml.netbeans.org/schema/users";
}

function productResolver(){
    return "http://xml.netbeans.org/schema/products";
}
function invoiceResolver(){
    return xmlns="http://xml.netbeans.org/schema/invoice";
}

function queryOneNode(xpath,doc,resolver){
    var node;
    var result;
    if (window.ActiveXObject){
        result = doc.selectNodes(xpath);
        node = result.item(0);
    } else {
        result = doc.evaluate(xpath, doc, resolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE ,null);
        node = result.iterateNext();
    }
    return node;
}
function queryLists(xpath,doc,resolver){
    var result;
    var nodeList;
    
    if (window.ActiveXObject){
        result = doc.selectNodes(xpath);
        nodeList = result;
        
    } else {
        nodeList = new Array();
        result = doc.evaluate(xpath, doc, resolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE ,null);

        var node = result.iterateNext();
        var i = 0;
        while (node) {
            nodeList[i] = node.cloneNode(true);
            node = result.iterateNext();
            i++;
        }
    }
    return nodeList;
}

function getNodeContent(obj) {
    var exp = "obj.text";
    if (!window.ActiveXObject) {
        exp += "Content";
    }
    return eval(exp);
}
function setNodeContent(obj,value) {
    var exp = "obj.text";
    if (!window.ActiveXObject) {
        exp += "Content";
    }
    exp += " value";
    eval(exp);
    return;
}

function showHideAccountInfo() {
    infoDiv = document.getElementById('accountInfo');
    if (infoDiv.style.display == '') {
        infoDiv.style.display = 'none';
    } else {
        infoDiv.style.display = '';
    }
}

function copyArray(arr) {
    var result = new Array();
    for(i=0; i < arr.length; i++) {
        result[i] = arr[i];
    }
    return result;
}

function getItems(Str){
    
    if (Str == null) return 0;
    var XMLDoc = stringtoXML(Str);
    
    var result = 0;
    for(var i = 0 ; i < XMLDoc.childNodes[0].childNodes.length ; i ++){
        result = parseInt(result) + parseInt(XMLDoc.childNodes[0].childNodes[i].childNodes[1].textContent);
    }
    
    return result;
}